Skip to content

Fix GetImplementingProperty issue when using interfaces#144

Merged
PhenX merged 6 commits intoEFNext:masterfrom
PhenX:copilot/fix-getimplementingproperty-issue
Mar 1, 2026
Merged

Fix GetImplementingProperty issue when using interfaces#144
PhenX merged 6 commits intoEFNext:masterfrom
PhenX:copilot/fix-getimplementingproperty-issue

Conversation

@PhenX
Copy link
Member

@PhenX PhenX commented Nov 23, 2025

Fixes #140

Copilot AI and others added 3 commits November 23, 2025 09:52
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
…ions

Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
@PhenX PhenX marked this pull request as ready for review November 23, 2025 12:35
fabien.menager added 2 commits March 1, 2026 09:57
# Conflicts:
#	src/EntityFrameworkCore.Projectables/Extensions/TypeExtensions.cs
@PhenX PhenX requested a review from Copilot March 1, 2026 09:02
@PhenX PhenX added this to the v6.0.0 milestone Mar 1, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #140, where GetImplementingProperty throws System.InvalidOperationException ("Sequence contains no matching element") when a class has both a public property and an explicit interface implementation property sharing the same name (e.g., int Id { get; set; } and string IStringId.Id => ...). The fix changes First(...) to FirstOrDefault(...) ?? propertyInfo in TypeExtensions.GetImplementingProperty, so that when the matching property cannot be found in the derived type's properties, the code gracefully falls back to returning the original interface property rather than throwing.

Changes:

  • The single-line source fix in TypeExtensions.GetImplementingProperty replaces First with FirstOrDefault and adds a ?? propertyInfo fallback to prevent the crash.
  • New unit tests and helper types added to TypeExtensionTests.cs verifying both GetImplementingProperty and GetConcreteProperty return the concrete explicit interface implementation (not the interface property) and do not throw.
  • New functional and generator snapshot tests added to validate end-to-end behavior for the explicit interface implementation scenario.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/EntityFrameworkCore.Projectables/Extensions/TypeExtensions.cs Core bug fix: changes First to FirstOrDefault with ?? propertyInfo fallback in GetImplementingProperty
tests/EntityFrameworkCore.Projectables.Tests/Extensions/TypeExtensionTests.cs Adds IStringId/ItemWithExplicitInterfaceImplementation helper types and two unit tests for the fix
tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs Adds generator-level snapshot test for a projectable property that accesses an interface member via cast
tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ExplicitInterfaceImplementation.verified.txt Snapshot verifying the generated expression tree for the new generator test
tests/EntityFrameworkCore.Projectables.FunctionalTests/ExplicitInterfaceImplementationTests.cs Adds functional tests exercising Select and Where on a class with an explicit interface implementation
tests/EntityFrameworkCore.Projectables.FunctionalTests/ExplicitInterfaceImplementation*.verified.txt (multiple) Verified SQL snapshots for DotNet 8/9/10 for both functional test methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@PhenX PhenX merged commit 07190c1 into EFNext:master Mar 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two properties with same name causes GetImplementingProperty to throw System.InvalidOperationException: Sequence contains no matching element

3 participants